<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>m修饰符</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
	span.red{
		color: red;
	}
    </style>
</head>
<body>
	<div class="container" id="container">
		<h1>m修饰符</h1> 
		<p>用于将内容视为多行匹配，主要是对 ^和 $ 的修饰</p>
	</div>
	<script src="../tools/utils.js"></script>
	<script type="text/javascript">
		var hd = `
	  #1 js,200元 #
	  #2 php,300元 #
	  #9 houdunren.com # 后盾人
	  #3 node.js,180元 #
	`;
	
	// [{name:'js',price:'200元'}]
	var reg = /#\d+\s+(.+?)\s*#/gs
	console.log(hd.match(reg))
	var matches = matchAll(reg, hd);

	/*
	var data = []
	matches.forEach(item => {
		if(!/\d+元/.test(item[1])) {
			return false
		}
		var [name, price] = item[1].split(',')
		data.push({name, price})
	})
	console.log(JSON.stringify(data, null, 2))
	*/

	// 采用map方法	
	var data = matches.map(item => {
		if(!/\d+元/.test(item[1])) {
			return false
		}
		var [name, price] = item[1].split(',')
		return {name, price}
	})
	console.log(JSON.stringify(data, null, 2))
 

	
	</script>
</body>
</html>